#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QAction>
#include<image.h>
//#include<Matrix.h>
#include<iostream>
#include<QByteArray>
#include<QPixmap>
#include<QDebug>
#include <QFileInfo>
#include<QInputDialog>
using namespace  std;


QString File;
QString File2;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //设置信号，点击那个open可以出现选项
    connect(ui->actionopen,&QAction::triggered,[=](){
        //打开的文件用filename 保存下来
   QString filename= QFileDialog::getOpenFileName(this,"选择图片;",QCoreApplication::applicationFilePath());
    //if successfully open
    qDebug()<<filename;
    File=filename;
  //  qDebug()<<File;
   if(filename.isEmpty()){
       QMessageBox::warning(this,"提示","请选择一张图");
   }

// 显示到屏幕
  QPixmap pix (filename);
   ui->label->setPixmap(pix);
    });

//    //*******************************
//    connect(ui->actionopen_3,&QAction::triggered,[=](){
//   QString filename2= QFileDialog::getOpenFileName(this,"选择图片;",QCoreApplication::applicationFilePath());
//    File2=filename2;

//   if(filename2.isEmpty()){
//       QMessageBox::warning(this,"提示","请选择一张图");
//   }
//});



}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_action2_triggered()
{
    char*  ch;
   QByteArray ba = File.toLatin1(); // must
   ch=ba.data();

     Image ima(ch);
    ima.cold(ch);
     QString file2="Copy.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);
}

void MainWindow::on_action_4_triggered()
{
    char*  ch;
    QByteArray ba = File.toLatin1(); // must
    ch=ba.data();

     Image ima(ch);
     ima.Flip(1);
      QString file2="Up.bmp";
      QImage* img=new QImage; //   **********
      if(! ( img->load(file2) ) ) //加载图像
      {
          delete img;
          return;
      }
      QPixmap pix (file2);
       ui->label_2->setPixmap(pix);

}

void MainWindow::on_action_2_triggered()
{
    char*  ch;
   QByteArray ba = File.toLatin1(); // must
   ch=ba.data();

     Image ima(ch);
    ima.Warm(ch);
     QString file2="Copy.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);

}

void MainWindow::on_action_5_triggered()
{
    char*  ch;
    QByteArray ba = File.toLatin1(); // must
    ch=ba.data();

     Image ima(ch);
     ima.Flip(0);
      QString file2="Left.bmp";
      QImage* img=new QImage; //   **********
      if(! ( img->load(file2) ) ) //加载图像
      {
          delete img;
          return;
      }
      QPixmap pix (file2);
       ui->label_2->setPixmap(pix);

}

void MainWindow::on_actiontetx_triggered()
{
    char*  ch;
    QByteArray ba = File.toLatin1(); // must
    ch=ba.data();

     Image ima(ch);
     ima.opposite(ch);
     QString file2="Copy.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);

}

void MainWindow::on_actiontest2_triggered()
{
    char*  ch;
    QByteArray ba = File.toLatin1(); // must
    ch=ba.data();

     Image ima(ch);
     ima.old(ch);
     QString file2="Copy.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);
}



void MainWindow::on_action90_triggered()
{
    char*  ch;
    QByteArray ba = File.toLatin1(); // must
    ch=ba.data();

     Image ima(ch);
     ima.Rotate(90);
     QString file2="degree90.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);
}

void MainWindow::on_action180_triggered()
{
    char*  ch;
    QByteArray ba = File.toLatin1(); // must
    ch=ba.data();

     Image ima(ch);
     ima.Rotate(180);
     QString file2="degree180.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);
}

void MainWindow::on_action270_triggered()
{
    char*  ch;
    QByteArray ba = File.toLatin1(); // must
    ch=ba.data();

     Image ima(ch);
     ima.Rotate(270);
     QString file2="degree270.bmp";
     QImage* img=new QImage; //   **********
     if(! ( img->load(file2) ) ) //加载图像
     {
         delete img;
         return;
     }
     QPixmap pix (file2);
      ui->label_2->setPixmap(pix);
}
